package com.hippo.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.hippo.core.config.annotation.RequiresPermissions;
import com.hippo.core.service.SceneService;
import com.hippo.core.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: hippo
 */
@RestController
public class SceneController {

    @Autowired
    private SceneService sceneService;

    @RequiresPermissions("scene:list")
    @GetMapping("/getSceneTree/{projectId}")
    public JSONObject getSceneList(@PathVariable String projectId) {
        return sceneService.getSceneList(projectId);
    }

    @RequiresPermissions("scene:add")
    @PostMapping("/addScene")
    public JSONObject addScene(@RequestBody JSONObject data) {
        return sceneService.addScene(data);
    }

    @RequiresPermissions("scene:delete")
    @PostMapping("/deleteScene")
    public JSONObject deleteScene(@RequestBody JSONObject obj) {
        return sceneService.deleteScene(obj);
    }

    @RequiresPermissions("scene:update")
    @PutMapping("updateScene")
    public JSONObject updateScene(@RequestBody JSONObject data) {
        return sceneService.updateScene(data);
    }

    @RequiresPermissions("scene_variable:list")
    @PostMapping("/getSceneVariableList")
    public JSONObject getSceneVariableList(@RequestBody JSONObject data) {
        return sceneService.getSceneVariableList(data);
    }

    @RequiresPermissions("scene_variable:add")
    @PostMapping("/addSceneVariable")
    public JSONObject addSceneVariable(@RequestBody JSONObject data) {
        CommonUtil.hasAllRequired(data, "name,value");
        return sceneService.addSceneVariable(data);
    }

    @RequiresPermissions("scene_variable:delete")
    @DeleteMapping("/deleteSceneVariable/{id}")
    public JSONObject deleteSceneVariable(@PathVariable String id) {
        return sceneService.deleteSceneVariable(id);
    }

    @RequiresPermissions("scene_variable:update")
    @PutMapping("updateSceneVariable")
    public JSONObject updateSceneVariable(@RequestBody JSONObject data) {
        CommonUtil.hasAllRequired(data, "name,value");
        return sceneService.updateSceneVariable(data);
    }

}
